pull: Print GPG signature status as soon as its known
authorMatthew Barnes <mbarnes@redhat.com>
Tue, 14 Apr 2015 00:26:21 +0000 (20:26 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Thu, 16 Apr 2015 22:13:08 +0000 (18:13 -0400)
src/ostree/ot-builtin-pull.c
src/ostree/ot-main.c
src/ostree/ot-main.h

index 91db17d1d4eb1f1b64190cdafb6600e75c479e9d..5d9eac42c877a4f5e72e8303a9c946604e42e0f5 100644 (file)
@@ -40,6 +40,20 @@ static int opt_depth = 0;
    { NULL }
  };
 
+static void
+gpg_verify_result_cb (OstreeRepo *repo,
+                      const char *checksum,
+                      OstreeGpgVerifyResult *result,
+                      GSConsole *console)
+{
+  /* Temporarily place the GSConsole stream (which is just stdout)
+   * back in normal mode before printing GPG verification results. */
+  gs_console_end_status_line (console, NULL, NULL);
+
+  g_print ("\n");
+  ostree_print_gpg_verify_result (result);
+}
+
 gboolean
 ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **error)
 {
@@ -51,6 +65,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
   GSConsole *console = NULL;
   gs_unref_ptrarray GPtrArray *refs_to_fetch = NULL;
   gs_unref_object OstreeAsyncProgress *progress = NULL;
+  gulong signal_handler_id = 0;
 
   context = g_option_context_new ("REMOTE [BRANCH...] - Download data from remote repository");
 
@@ -100,6 +115,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
     {
       gs_console_begin_status_line (console, "", NULL, NULL);
       progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console);
+      signal_handler_id = g_signal_connect (repo, "gpg-verify-result",
+                                            G_CALLBACK (gpg_verify_result_cb),
+                                            console);
     }
 
   {
@@ -116,7 +134,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
                              g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch->pdata, -1)));
     g_variant_builder_add (&builder, "{s@v}", "depth",
                            g_variant_new_variant (g_variant_new_int32 (opt_depth)));
-    
+   
     if (!ostree_repo_pull_with_options (repo, remote, g_variant_builder_end (&builder),
                                         progress, cancellable, error))
       goto out;
@@ -127,6 +145,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
 
   ret = TRUE;
  out:
+  if (signal_handler_id > 0)
+    g_signal_handler_disconnect (repo, signal_handler_id);
+
   if (console)
     gs_console_end_status_line (console, NULL, NULL);
  
index 76dbb5c8ee5741ec326914b55a9276fb3c977e90..457aa3c45d3225c916c55932ab4419c2fb9371fd 100644 (file)
@@ -385,3 +385,27 @@ ostree_ensure_repo_writable (OstreeRepo *repo,
 
   return ret;
 }
+
+void
+ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result)
+{
+  GString *buffer;
+  guint n_sigs, ii;
+
+  n_sigs = ostree_gpg_verify_result_count_all (result);
+
+  /* XXX If we ever add internationalization, use ngettext() here. */
+  g_print ("Found %u signature%s:\n", n_sigs, n_sigs == 1 ? "" : "s");
+
+  buffer = g_string_sized_new (256);
+
+  for (ii = 0; ii < n_sigs; ii++)
+    {
+      g_string_append_c (buffer, '\n');
+      ostree_gpg_verify_result_describe (result, ii, buffer, "  ",
+                                         OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT);
+    }
+
+  g_print ("%s", buffer->str);
+  g_string_free (buffer, TRUE);
+}
index 2ea57552ca91a995e250df4a31cb9ff1961770f6..60ddb36ac4162c4e1812878123281e4625a64e27 100644 (file)
@@ -59,3 +59,5 @@ gboolean ostree_admin_option_context_parse (GOptionContext *context,
                                             GCancellable *cancellable, GError **error);
 
 gboolean ostree_ensure_repo_writable (OstreeRepo *repo, GError **error);
+
+void ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result);